<?php
$title = ___("Payments History");
$this->headScript()->appendFile($this->_scriptJs('user.js'));
$this->setLayout('member/layout.phtml');
?>

<?php if ($activeInvoices): ?>
<h2><?php __e('Your Active Subscriptions') ?></h2>
<?php foreach ($activeInvoices as $invoice): ?>
<?php include $this->_script('member/_invoice.phtml'); ?>
<?php endforeach ?>
<?php endif ?>

<?php if ($payments): ?>
<div class="grid-container">
<table class="grid">
    <tr>
    <th><?php __e('Date') ?></th>
    <th><?php __e('Invoice') ?></th>
    <th><?php __e('Products') ?></th>
    <th><?php __e('Payment System') ?></th>
    <th><?php __e('Amount') ?></th>
    <?php if ($di->config->get('send_pdf_invoice')): ?><th><?php __e('PDF Invoice') ?></th><?php endif ?>
    </tr>
<?php foreach ($payments as $p): ?>
    <tr>
    <td><?php echo amDate($p->dattm)?></td>
    <td align="right"><?php echo $p->getInvoice()->public_id ?></td>
    <td><?php
        $products = $p->getInvoice()->getProducts();
        echo join(', ',  array_map(create_function('$p', 'return $p->title;'), $products));
    ?></td>
    <td><?php p($p->_paysysName) ?></td>
    <td align="right"><?php echo $p->getCurrency($p->amount) ?>&nbsp;</td>
    <?php if ($di->config->get('send_pdf_invoice')): ?><td><a href="<?php $this->pUrl('member', 'get-invoice', 'default', 'id', $p->pk())?>"><?php __e('Invoice') ?></a></td><?php endif ?>
    </tr>
<?php endforeach ?>
</table>
</div>
<?php else: // if ($payments):?>
<?php __e('There are no confirmed payments for your account'); ?>
<?php endif // if ($payments): ?>

<div class="cancel-subscription-popup" style="display:none">
<?php include $this->_script('member/_cancel.phtml') ?>    
</div>

<?php foreach ($activeInvoices as $invoice): if (!empty($invoice->_upgrades)) : ?>
<div class="upgrade-subscription-popup upgrade-subscription-popup-<?php echo $invoice->invoice_id ?>" style="display:none">
<?php include $this->_script('member/_upgrade.phtml') ?>    
</div>
<?php endif; endforeach ?>